package com.ethink.platform.job;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.ethink.report.common.mapper.MateInventoryHistoryMapper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;
import java.util.Date;

@Slf4j
@Component
public class MateInventoryHistoryJob {

    @Autowired
    private MateInventoryHistoryMapper mateInventoryHistoryMapper;

    @XxlJob("MateInventoryHistoryJob")
    @Transactional(rollbackFor = Exception.class)
    public void run() {
        log.info("====================== MateInventoryHistoryJob start ======================");
        Date now = new Date();
        String repDate = DateUtil.format(DateUtil.offsetDay(now, -1), DatePattern.PURE_DATE_FORMAT);
        String month = repDate.substring(0,6);
        mateInventoryHistoryMapper.deleteHistory(month, repDate);
        mateInventoryHistoryMapper.batchInsert(month, repDate);
        log.info("====================== MateInventoryHistoryJob end ======================");
    }

}
